<include file="../header" />
</head>
<body class="J_scroll_fixed">
<script type="text/javascript">
    $(function() {
        $("input[name=checkAll]").click(function() {
            var checkboxs = $("input.checkItem");
            if($("input[name=checkAll]").is(':checked')) {
                for(var i = 0 ;i<checkboxs.length;i++) {
                    checkboxs[i].checked = true;
                }
            }else{
                for(var i = 0 ;i<checkboxs.length;i++) {
                    checkboxs[i].checked = false;
                }
            }
        });

        $("button#upload").click(function(){
            //上传文件
            $.ajaxFileUpload({
                url:"{:U('activity/uploadImage')}",//处理图片脚本
                secureuri :false,
                fileElementId :'fileToUpload',//file控件id
                dataType : 'json',
                success : function (data, status){
                    $("input[name=signimgurl]").val(data);
                    $("img[name=preShow]").attr("src", data);
                },
                error: function(data, status, e){
                    alert(e);
                }
            })

        });

        $("button.btn_submit").click(function() {
            if ($("input[name=adminName]").val() == "") {
                alert("【姓名】不能为空");
                $("input[name=adminName]").focus();
                return false;
            }

//            if ($("input[name=name]").val() != "" && $("input[name=password]").val() == "") {
//                alert("【密码】不能为空");
//                $("input[name=password]").focus();
//                return false;
//            }

            var checkboxs = $("input.checkItem");
            var id = "";
            for (var i = 0; i < checkboxs.length; i++) {
                if(checkboxs[i].checked == true){
                    if(id != ""){
                        id += ",";
                    }
                    id += checkboxs[i].name;
                }
            }
            $("input[name=agentId]").val(id);

            $("button.btn_submit").hide();

        })

    })

</script>
	<div class="wrap jj">
		<ul class="nav nav-tabs">
			<li><a href="{:U('user/employee')}">员工管理</a></li>
			<li><a href="{:U('user/add')}">添加员工</a></li>
		</ul>
		<div class="common-form">
			<form method="post" class="form-horizontal J_ajaxForm" action="{:U('User/edit_post')}">
                            <input type="hidden" name="user_id" value="{$user.user_id}" />
				<fieldset>
					<div class="control-group">
						<label class="control-label">企业名称:</label>
						<div style="line-height: 30px; font-size: 1.2rem" class="controls">
							{$user.enterprise_name}
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">姓名:</label>
						<div class="controls">
							<input type="text" class="input" name="adminName" value="{$user.admin_name}">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">电话:</label>
						<div class="controls">
							<input type="text" class="input" name="mobile" value="{$user.mobile}">
						</div>
					</div>

					<div class="control-group">
						<label class="control-label">用户名:</label>
						<div class="controls">
							<input autocomplete="off" type="text" class="input" name="name" value="{$user.name}">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">密码:</label>
						<div class="controls">
							<input autocomplete="off" type="text" class="input" name="password" placeholder="********">
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">角色:</label>
						<div class="controls">
							<foreach name="roles" item="vo">
							<label class="checkbox inline">
								<php>$role_id_checked=in_array($vo['id'],$role_ids)?"checked":"";</php>
								<input value="{$vo.id}" type="checkbox" name="role_id[]" {$role_id_checked}>{$vo.name}
							</label>
							</foreach>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">签名图片:</label>
						<div class="controls">
							<input id="fileToUpload" type="file" name="fileToUpload" style="width:170px;">
							<button type="button" class="btn btn-primary" id="upload">上传</button>
							<input type="hidden" name="signimgurl" value="{$user.signimgurl}"/>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">签名预览:</label>
						<div class="controls">
							<img src="{$user.signimgurl}" name="preShow"/>
						</div>
					</div>
					<div class="control-group">
						<label class="control-label">备注:</label>
						<div style="line-height: 30px;color: #df5c72; font-size: 1rem"  class="controls">
							{$user.note}
						</div>
					</div>
					<hr class="half-rule">
					<table class="table table-hover table-bordered" id="viewTabs" style="width: 400px; margin-left: 90px">
						<thead>
						<tr>
							<th style="min-width: 10px; width: 10px"><input type="checkbox" name="checkAll"></th>
							<th style="min-width: 100px; width: 200px">渠道</th>
						</tr>
						</thead>
						<tbody>
						<foreach name="list" item="vo">
							<tr>
								<php>
									$agent_checked=($vo['has_agent'] == 1)?"checked":"";
								</php>
								<td><input type="checkbox" class="checkItem" name="{$vo.agent_id}" {$agent_checked}></td>
								<td style="font-size: 1rem">{$vo.agent_id}.{$vo.agent_name}</td>
							</tr>
						</foreach>
						</tbody>
					</table>
					<input type="hidden" name="agentId" value="" style="width: 200px"/>

					<div class="control-group">
						<label class="control-label">上次更新:</label>
						<div style="line-height: 30px;color: #61a4de; font-size: 1rem" class="controls">
							[{$user.update_time}] {$updateName}
						</div>
					</div>
				</fieldset>
				<div class="form-actions">
					<input type="hidden" name="id" value="{$id}" />
					<button type="submit" class="btn btn-primary btn_submit">更新</button>
					<a class="btn" href="{:u('User/employee')}">返回</a>
				</div>
			</form>
		</div>
	</div>
	<script src="__ROOT__/statics/js/common.js"></script>
</body>
</html>